#include <QtGui>
#include <windows.h>
#include "mainwindow.h"
#include <iostream>
#include <QSharedMemory>
#include "qtsingleapplication.h"

int main(int argc, char *argv[])
{
    QtSingleApplication app(argc, argv);

    QString local = QLocale::system().name();
    QTranslator tran;

    if(!tran.load(QString("locale/lua_") + local))
        qDebug() << "Failed to load locale files!!";

    app.installTranslator(&tran);


    if( app.isRunning() )
    {
        QString msg;
        for(int i = 1; i < argc; ++i)
        {
            msg = argv[i];
            app.sendMessage(msg);
        }

        return 0;
    }
    else
    {
        MainWindow* wnd = MainWindow::getWnd();


        if(argc > 1)
        {
            for(int i = 1; i < argc; ++i)
                wnd->instantOpen(QString(argv[i]));
        }

        wnd->show();

        QObject::connect(&app, SIGNAL(messageReceived(const QString&)), wnd, SLOT(instantOpen(const QString&)));

        return app.exec();
    }
}
